import {
  HttpApi
} from '../../../model/index.js'
const httpApi = new HttpApi

Page({
  data: {
    windowHeight: 100,
    records: [],
    start: 1,
    size: 300,
    loading: false,
    content: "",
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var login = wx.getStorageSync('login')
    
    this.getData(this.data.start, this.data.size)
    //设置scroll-view高度
    wx.getSystemInfo({
      success: function (res) {
        that.setData({ windowHeight: res.windowHeight });
      }
    });
  },
  getData(_start, _size) {
    this.loading = true
    var _this = this
    httpApi.feedbackList(_start, _size).then(res => {
      console.log("feedbackList:", res.data)
      var records = res.data.records;
      for (var i = 0; i < records.length;i++){
        var index = records[i].content.lastIndexOf('"');
        records[i].content = records[i].content.substring(22, index);
      }
      console.log("records:", records)
      _this.setData({
        start: _start,
        records: records,
        loading: false,
      })
    })
  },

  onReachBottom() {
    console.log("reachbottom")
    // 下拉触底，先判断是否有请求正在进行中
    // 以及检查当前请求页数是不是小于数据总页数，如符合条件，则发送请求
    if (!this.loading) {
      this.getData(this.data.start + this.data.size, this.data.size)
    }
  },

  // 新增反馈意见
  addFeedback() {
    wx.navigateTo({ url: 'newFeedback/newFeedback' });
  },
  

})
